package cqrtplm.controller;

import com.hustcad.plm.pdm.file.handler.response.ResponseResult;
import com.ty.basic.constant.ApiPathConstant;
import cqrtplm.dto.ImportProjectRiskDTO;
import cqrtplm.service.ProjectRiskFormService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(ApiPathConstant.PRODUCT_VERSION_ONE_PATH + "risk")
public class ProjectRiskFormController {
    @Resource
    private ProjectRiskFormService projectRiskFormService;

    @PostMapping("getRiskFileData")
    public ResponseResult<List<ImportProjectRiskDTO>> importProjectRisk(MultipartFile file) throws Exception{
        List<ImportProjectRiskDTO> data = projectRiskFormService.getRiskFileData(file);
        return ResponseResult.success(data,"获取风险信息成功");
    }

    @PostMapping("batchCreateRiskFileData")
    public ResponseResult importProjectRisk(@RequestBody List<ImportProjectRiskDTO> data){
        try {
            projectRiskFormService.batchCreateRiskFileData(data);
        } catch (Exception e) {
            String message = e.getMessage();
            return ResponseResult.fail("400","创建失败",message);
        }
        return ResponseResult.success("创建成功");
    }
}
